package com.hyh.search.controller;

import com.hyh.search.result.PageResult;
import com.hyh.search.service.ProductService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;


@RestController
@RequestMapping("/api/es")
public class ProController {

    @Autowired
    private ProductService productService;

    /*
     * @description: 获取全部商品信息
     * @param:
     * @return:
     * @author
     * @date: 2024/3/19 12:54
     */
    @GetMapping("/list")
    public PageResult getAllProduct(){
        return productService.selectAllProduct();
    }


    /*
     * @description: 自动补全
     * @param:
     * @return:
     * @author
     * @date: 2024/3/19 20:23
     */
    @GetMapping("/suggestion")
    public PageResult getSuggestion(@RequestParam("key") String key) {
        return productService.getSuggestion(key);
    }



    /*
     * @description: 查询所有的商品分页查询
     * @param:
     * @return:
     * @author
     * @date: 2024/3/20 10:54
     */
    @GetMapping("/searchAll")
    public PageResult search(@RequestParam("page") Integer page,
                             @RequestParam("size") Integer size){
        return productService.searchAll(page,size);
    }

    /*
     * @description: 根据title查询商品 分页查询
     * @param:
     * @return:
     * @author
     * @date: 2024/3/19 20:25
     */
    @PostMapping("/search")
    public PageResult search(@RequestParam("key") String key ,
                             @RequestParam("page") Integer page,
                             @RequestParam("size") Integer size){
        return productService.search(key,page,size);
    }


    /*
     * @description: 复合查询 价格和关键词条
     * @param:
     * @return:
     * @author
     * @date: 2024/3/20 13:46
     */
    @PostMapping("/searchByPrice")
    public PageResult searchByPrice(@RequestParam("key") String key ,
                                    @RequestParam("page") Integer page,
                                    @RequestParam("size") Integer size,
                                    @RequestParam(value = "min",required = false) Integer min,
                                    @RequestParam(value = "max",required = false) Integer max){
        return productService.searchByPrice(key,page,size,min,max);
    }
}
